﻿using System;
using System.Windows;
using System.Windows.Threading;
using YsTiffConverter.ViewModel;

namespace YsTiffConverter
{
    /// <summary>
    /// Interaction logic for SaveAllFramesWindow.xaml
    /// </summary>
    public partial class SaveAllFramesWindow : Window
    {
        #region Fields

        #endregion Fields

        #region Properties

        /// <summary>
        /// Gets or sets the SaveAllFramesWindowViewModel.
        /// </summary>
        private SaveAllFramesWindowViewModel SaveAllFramesWindowViewModel
        {
            get;
            set;
        }
        #endregion Properties

        /// <summary>
        /// Initializes a new instance of the SaveAllFramesWindow class.
        /// </summary>
        /// <param name="fileName"></param>
        public SaveAllFramesWindow(string fileName)
        {
            InitializeComponent();

            SaveAllFramesWindowViewModel = new SaveAllFramesWindowViewModel(fileName);
            SaveAllFramesWindowViewModel.OnSaved += OnCompleted;
        }

        /// <summary>
        /// Handles the close button click.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonCloseClick(object sender, RoutedEventArgs e)
        {
            Close();
        }

        /// <summary>
        /// Handles the event "window loaded".
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event arguments.</param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            DataContext = SaveAllFramesWindowViewModel;
        }

        /// <summary>
        /// Is calling on batch save completing.
        /// </summary>
        public void OnCompleted()
        {
            Dispatcher.Invoke(DispatcherPriority.Normal,
                              ((Action)Close));
        }
    }
}
